package com.rykj.qxj.rest;

import com.github.pagehelper.PageInfo;
import com.rykj.qxj.server.model.entity.SystemParameter;
import com.rykj.qxj.server.services.ISystemParameterService;
import com.rykj.qxj.util.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.log4j.Log4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Log4j
@RestController
@RequestMapping("/v1/systemParameter")
@Api(tags="系统参数")
public class SystemParameterController {
	@Autowired
	private ISystemParameterService systemParameterService;
	@PostMapping("/save")
    @ApiOperation(value="保存系统参数",notes ="保存系统参数")
	public Result save(@RequestBody SystemParameter systemParameter) {
		try {
			systemParameterService.save(systemParameter);
			return new Result(true, "保存成功");
		} catch (Exception e) {
			log.error("保存失败", e);
			return new Result(false, "保存失败");
		}
	}
	@PostMapping("/update")
    @ApiOperation(value="修改系统参数",notes ="修改系统参数")
    public Result update(@RequestBody SystemParameter systemParameter){
		if(systemParameter.getId()==null) {
			return new Result(false, "配置信息修改的Id不能为null");
		}
		try {
			systemParameterService.update(systemParameter);
			return new Result(true, "修改成功");
		} catch (Exception e) {
			log.error("修改失败", e);
			return new Result(false, "修改失败");
		}
    }
	@GetMapping("/list")
    @ApiOperation(value="系统参数分页列表",notes ="系统参数分页列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum", value = "当前页数",required = true,paramType = "query"),
            @ApiImplicitParam(name = "pageSize", value = "显示行数",required = true,paramType = "query"),
            @ApiImplicitParam(name = "name", value = "等级名称",paramType = "query")
    })
    public Result selectSystemParameterBySearchParams(@RequestParam(value = "pageNum") Integer pageNum,
                                   @RequestParam(value = "pageSize") Integer pageSize,
                                   @RequestParam(value = "name",required = false) String name){
        try{
		PageInfo page = systemParameterService.selectSystemParameterBySearchParams(pageNum, pageSize, name);
            return new Result(page);
        }catch (Exception e){
            log.error("查询失败", e);
            return new Result(false, "查询失败");
        }
        
    }

}
